package com.ruoyi.purchase.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.purchase.domain.BizPurchaseReceive;
import com.ruoyi.purchase.service.IBizPurchaseReceiveService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购收货记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/purchase/receive")
public class BizPurchaseReceiveController extends BaseController
{
    private String prefix = "purchase/receive";

    @Autowired
    private IBizPurchaseReceiveService bizPurchaseReceiveService;

    @RequiresPermissions("purchase:receive:view")
    @GetMapping()
    public String receive()
    {
        return prefix + "/receive";
    }

    /**
     * 查询采购收货记录列表
     */
    @RequiresPermissions("purchase:receive:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizPurchaseReceive bizPurchaseReceive)
    {
        startPage();
        List<BizPurchaseReceive> list = bizPurchaseReceiveService.selectBizPurchaseReceiveList(bizPurchaseReceive);
        return getDataTable(list);
    }

    /**
     * 导出采购收货记录列表
     */
    @RequiresPermissions("purchase:receive:export")
    @Log(title = "采购收货记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizPurchaseReceive bizPurchaseReceive)
    {
        List<BizPurchaseReceive> list = bizPurchaseReceiveService.selectBizPurchaseReceiveList(bizPurchaseReceive);
        ExcelUtil<BizPurchaseReceive> util = new ExcelUtil<BizPurchaseReceive>(BizPurchaseReceive.class);
        return util.exportExcel(list, "采购收货记录数据");
    }

    /**
     * 新增采购收货记录
     */
    @RequiresPermissions("purchase:receive:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购收货记录
     */
    @RequiresPermissions("purchase:receive:add")
    @Log(title = "采购收货记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizPurchaseReceive bizPurchaseReceive)
    {
        return toAjax(bizPurchaseReceiveService.insertBizPurchaseReceive(bizPurchaseReceive));
    }

    /**
     * 修改采购收货记录
     */
    @RequiresPermissions("purchase:receive:edit")
    @GetMapping("/edit/{receiveId}")
    public String edit(@PathVariable("receiveId") Long receiveId, ModelMap mmap)
    {
        BizPurchaseReceive bizPurchaseReceive = bizPurchaseReceiveService.selectBizPurchaseReceiveByReceiveId(receiveId);
        mmap.put("bizPurchaseReceive", bizPurchaseReceive);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购收货记录
     */
    @RequiresPermissions("purchase:receive:edit")
    @Log(title = "采购收货记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizPurchaseReceive bizPurchaseReceive)
    {
        return toAjax(bizPurchaseReceiveService.updateBizPurchaseReceive(bizPurchaseReceive));
    }

    /**
     * 删除采购收货记录
     */
    @RequiresPermissions("purchase:receive:remove")
    @Log(title = "采购收货记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizPurchaseReceiveService.deleteBizPurchaseReceiveByReceiveIds(ids));
    }
}
